<template>
	<view class="coupons-wrapper mask" @tap.stop="close">
		<view class="coupons-content" @tap.stop>
			<view class="coupons-title padding-h">
				<text class="text">红包</text>
				<text class="icon new-iconfont icon-close" @tap="close"></text>
			</view>
			<view class="tabs">
				<view class="tab-item" :class="{active:current===0}" :data-current="0" @tap="currentChange">
					可用红包
				</view>
				<view class="tab-item" :class="{active:current===1}" :data-current="1" @tap="currentChange">
					不可用红包
				</view>
			</view>
			<swiper :current="current" @change="currentChange2">
				<swiper-item>
					<scroll-view scroll-y>
						<view class="coupon-list margin-h">
							<CouponItem :coupon="item" v-for="item in usableCoupons" :key="item.uuid"
								:isSelected="currentCoupon.id === item.id" :active="1" @click="onClick(item)"
								:background-color="false?'rgba(245, 35, 2, 0.1)':'#ffffff'"
								:totalprice="totalprice"></CouponItem>
							<view style="height: 80vh;overflow: hidden;" v-if="!usableCoupons.length">
								<NoData ></NoData>
							</view>
							
						</view>
					</scroll-view>
				</swiper-item>
				<swiper-item>
					<scroll-view scroll-y>
						<view class="coupon-list margin-h">
							<CouponItem :coupon="item" v-for="item in unusableCoupons" :key="item.uuid" :active="0"
								unActiveText="不可用"></CouponItem>
								<view style="height: 80vh;overflow: hidden;"  v-if="!unusableCoupons.length">
									<NoData></NoData>
								</view>
							
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import CouponItem from "./components/CouponItem.vue"
	export default {
		components: {
			CouponItem
		},
		props: {
			unusableCoupons: {
				type: Array
			},
			usableCoupons: {
				type: Array
			},
			currentCoupon: {
				type: Object,
				default: () => {
					return {}
				}
			},
			totalprice:{
				type:String
			}
		},
		data() {
			return {
				current: 0
			}
		},
		computed: {},
		mounted() {
		},
		methods: {
			close() {
				this.$emit('close')
			},
			currentChange(e) {
				let index = e.currentTarget.dataset.current
				if (index === this.current) return
				this.current = index
			},
			currentChange2(e) {
				let index = e.detail.current
				if (index === this.current) return
				this.current = index
			},
			onClick(item) {
				console.log(item);
				this.$emit('change', item)
				this.$emit('close')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.coupons-wrapper {}

	.icon {
		color:#fff;
	}

	.coupons-content {
		width: 100%;
		height: 70%;
		position: absolute;
		bottom: 0;
		left: 0;
		border-radius: 20rpx 20rpx 0 0;
		background: rgb(26, 23, 36);
		border: 3rpx solid #5d4748;

		.coupons-title {
			height: 94upx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.text {
				font-size: 34upx;
				color:white;
			}
		}

		.tabs {
			display: flex;

			.tab-item {
				flex: 1;
				height: 90upx;
				line-height: 90upx;
				text-align: center;
				position: relative;
				font-size: 28upx;
				color:white;
				&.active {
					color: white;

					&::after {
						content: "";
						position: absolute;
						height: 2px;
						left: 40upx;
						right: 40upx;
						bottom: 0;
						background-color: white;

					}
				}
			}
		}

		swiper {
			width: 100%;
			height: calc(100% - 184upx);
			// background-color: #f5f5f5;

			scroll-view {
				width: 100%;
				height: 100%;

				.coupon-list {
					overflow: hidden;
				}
			}
		}
	}
</style>